package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.Course;
import cn.xgj.sfzy.entity.CourseTalk;
import cn.xgj.sfzy.entity.User;
import cn.xgj.sfzy.mapper.CourseReplyMapper;
import cn.xgj.sfzy.mapper.CourseTalkMapper;
import cn.xgj.sfzy.mapper.UserMapper;
import cn.xgj.sfzy.service.CourseTalkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CourseTalkServiceImpl
 * @Description TODO
 * @Author furuyue
 * @Date 2024年10月29日 16:41
 * @Version 1.0
 */

@Service
public class CourseTalkServiceImpl implements CourseTalkService {

    @Autowired
    private CourseTalkMapper courseTalkMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public CourseTalk findById(Long id) {
         return courseTalkMapper.findById(id);
    }

    @Override
    public PageInfo<CourseTalk> findByCourseIdAndPage(Long courseId,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CourseTalk> courseTalkList = courseTalkMapper.findByCourseId(courseId);
        for (CourseTalk courseTalk : courseTalkList) {
            User user = userMapper.findById(Math.toIntExact(courseTalk.getUserId()));
            courseTalk.setUser(user);
        }
        PageInfo<CourseTalk> pageInfo = new PageInfo<>(courseTalkList);
        return pageInfo;
    }
}
